/*
 * Copyright (c) 2014, S.F. Express Inc. All rights reserved.
 */
package org.jasig.cas.client.ext;

import org.jasig.cas.client.util.ReflectUtils;
import org.jasig.cas.client.validation.Assertion;
import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
import org.jasig.cas.client.validation.TicketValidationException;
import org.jasig.cas.client.validation.TicketValidator;

/**
 * 描述：ServiceTicketValidator
 * 
 * <pre>
 * HISTORY
 * ****************************************************************************
 *  ID   DATE            PERSON          REASON
 *  1    2015年12月24日     014767          Create
 * ****************************************************************************
 * </pre>
 * 
 * @author 014767
 * @since 1.0
 */
public class ServiceTicketValidator {

    /** ticketValidator */
    private TicketValidator ticketValidator;

    public ServiceTicketValidator(String casServerUrlPrefix) {
        if (!casServerUrlPrefix.endsWith("/")) {
            casServerUrlPrefix += "/";
        }
        ticketValidator = ReflectUtils.newInstance(Cas20ServiceTicketValidator.class, casServerUrlPrefix);
    }

    /**
     * 验证ST
     * 
     * @param ticket
     * @param serviceUrl
     * @return
     * @throws TicketValidationException
     */
    public Assertion validate(String ticket, String serviceUrl) throws TicketValidationException {
        return ticketValidator.validate(ticket, serviceUrl);
    }
}
